home *** CD-ROM | disk | FTP | other *** search
- var PROT_globalStore;
- var PROT_listManager;
- var PROT_phishingWarden;
- function PROT_Application() {
- this.debugZone= "application";
- function runUnittests() {
- if (G_GDEBUG) {
- G_DebugL("UNITTESTS", "STARTING UNITTESTS");
- TEST_G_Protocol4Parser();
- TEST_G_Base64();
- TEST_G_CryptoHasher();
- TEST_PROT_EnchashDecrypter();
- TEST_PROT_TRTable();
- TEST_PROT_ListManager();
- TEST_PROT_ListWarden();
- TEST_PROT_PhishingWarden();
- TEST_PROT_TRFetcher();
- TEST_G_ObjectSafeMap();
- TEST_PROT_URLCanonicalizer();
- TEST_G_Preferences();
- TEST_G_Observer();
- TEST_G_File();
- TEST_PROT_WireFormat();
- TEST_PROT_UrlCrypto();
- TEST_PROT_UrlCryptoKeyManager();
- TEST_G_MozVersionNumber();
- TEST_G_ThisFirefoxVersion();
- G_DebugL("UNITTESTS", "END UNITTESTS");
- }
- };
- PROT_globalStore =
- new PROT_GlobalStore("google.toolbar.button_option.safebrowsing.",
- this.getLocale());
- var prefs = new G_Preferences();
- if (!prefs.getPref(PROT_globalStore.getHaveRunBeforePrefName(), false)) {
- prefs.setPref(PROT_globalStore.getHaveRunBeforePrefName(), true);
- var optedIn = prefs.getPref(PROT_globalStore.getToolbarPageRankPrefName(),
- false);
- G_Debug(this, "First run of SafeBrowsing. Disabling advanced " +
- "due to page rank being off? " +
- (optedIn === false));
- prefs.setPref(PROT_globalStore.getServerCheckEnabledPrefName(), optedIn);
- prefs.setPref(PROT_globalStore.getServerCheckEnabledDefaultPrefName(),
- optedIn);
- }
- PROT_listManager = new PROT_ListManager();
- PROT_phishingWarden = new PROT_PhishingWarden(PROT_listManager);
- var threadConfig = {
- "interleave": true,
- "runtime": 80,
- "delay": 700,
- };
- var threadQueue = new TH_ThreadQueue(threadConfig);
- this.contentAnalyzer = new PROT_ContentAnalyzer(PROT_phishingWarden,
- threadQueue,
- false /* testing */);
- new PROT_UrlCryptoKeyManager();
- runUnittests();
- PROT_listManager.maybeStartManagingUpdates();
- }
- PROT_Application.isCompatibleWithThisFirefox = function() {
- var z = "application";
- var compatibleVersion = (new G_ThisFirefoxVersion()).isVersionOf("1.5");
- G_Debug(z, "Firefox version is compatible (1.5)? " + compatibleVersion);
- var binaryCompatible = false;
- var dbcomp = Cc["@google.com/dbupdateservice;1"];
- if (dbcomp)
- binaryCompatible = true;
- G_Debug(z, "Binary compatible? " + binaryCompatible);
- var extensionInstalled = false;
- try {
- var em = Cc["@mozilla.org/extensions/manager;1"]
- .getService(Ci.nsIExtensionManager);
- var loc = em.getInstallLocation("safebrowsing@google.com");
- if (loc != null)
- extensionInstalled = true;
- } catch(e) {
- dump("Masked in isCompatibleWithThisFirefox: " + e);
- }
- G_Debug(z, "SafeBrowsing extension already installed? " +
- extensionInstalled);
- return !extensionInstalled && compatibleVersion && binaryCompatible;
- }
- PROT_Application.prototype.getLocale = function() {
- var locale = 'en';
- var languages = {
- 'da-DK': 'da',
- 'de-DE': 'de',
- 'en-US': 'en',
- 'es-ES': 'es',
- 'fi-FI': 'fi',
- 'fr-FR': 'fr',
- 'it-IT': 'it',
- 'ja-JP': 'ja',
- 'ja-JPM': 'ja',
- 'ko-KR': 'ko',
- 'nb-NO': 'no',
- 'nl-NL': 'nl',
- 'pt-BR': 'pt-BR',
- 'ru-RU': 'ru',
- 'sv-SE': 'sv',
- 'zh-CN': 'zh-CN',
- 'zh-TW': 'zh-TW'
- }
- try {
- var prefs = new G_Preferences()
- var maybeLocale = prefs.getPref('general.useragent.locale', 'en-US');
- if (languages[maybeLocale]) {
- locale = languages[maybeLocale];
- } else {
- locale = maybeLocale.substr(0, 2);
- }
- } catch (e) {
- G_Debug(this, "Failed to get language: " + e);
- }
- return locale;
- }
- function PROT_ApplicationDirectory() {
- this.debugZone = "appdir";
- this.appDir_ = G_File.getProfileFile();
- this.appDir_.append(PROT_globalStore.getAppDirectoryName());
- G_Debug(this, "Application directory is " + this.appDir_.path);
- }
- PROT_ApplicationDirectory.prototype.exists = function() {
- return this.appDir_.exists() && this.appDir_.isDirectory();
- }
- PROT_ApplicationDirectory.prototype.create = function() {
- G_Debug(this, "Creating app directory: " + this.appDir_.path);
- try {
- this.appDir_.create(Ci.nsIFile.DIRECTORY_TYPE, 0700);
- } catch(e) {
- G_Error(this, this.appDir_.path + " couldn't be created.");
- }
- }
- PROT_ApplicationDirectory.prototype.getAppDirFileInterface = function() {
- return this.appDir_;
- }
-